/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.purpose.controller;

import com.koron.purpose.utils.BusinessCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.swan.bean.MessageBean;

import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.purpose.domain.SafetyOrgStaff;
import com.koron.purpose.service.api.SafetyOrgStaffService;
import com.koron.system.annotation.Log;
import com.koron.system.discrete.BusinessManipulation;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "safetyOrgStaff", description = "安全机构人员接口")
@RestController
@RequestMapping("/safetyOrgStaff")
public class SafetyOrgStaffController {

    @Autowired
    private SafetyOrgStaffService service;

    @ApiOperation("删除")
    @ApiImplicitParam(name = "id", value = "id",  paramType = "query", dataType = "String")
    @RequestMapping(value = "/delete.htm", method = {RequestMethod.POST})
    @Log(title = "删除机构人员",businessModule = "安全机构人员", businessManipulation = BusinessManipulation.DELETE)
    public MessageBean<?> delete(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String id) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.delete(id);
    }

    @ApiOperation("详情")
    @ApiImplicitParam(name = "id", value = "id",  paramType = "query", dataType = "String")
    @RequestMapping(value = "/details.htm", method = {RequestMethod.POST})
    public MessageBean<?> details(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String id) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.queryById(id);
    }

    @ApiOperation("添加人员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "staffCode", value = "人员code",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "staffName", value = "人员name",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "deptCode", value = "部门code",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "deptName", value = "部门name",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "phone", value = "电话",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "note", value = "描述",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orgRole", value = "角色",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isleader", value = "是否领导：0否1是",  paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "serial", value = "排序号",  paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "orgId", value = "机构id",  paramType = "query", dataType = "String")})
    @RequestMapping(value = "/insert.htm", method = {RequestMethod.POST})
    @Log(title = "机构添加人员", businessModule = "安全机构人员",businessManipulation = BusinessManipulation.INSERT)
    public MessageBean<?> insert(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore SafetyOrgStaff bean) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.insert(bean, user);
    }

    @ApiOperation("修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "staffCode", value = "人员code",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "staffName", value = "人员name",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "deptCode", value = "部门code",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "deptName", value = "部门name",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "phone", value = "电话",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "note", value = "描述",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orgRole", value = "角色",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isleader", value = "是否领导：0否1是",  paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "serial", value = "排序号",  paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "orgId", value = "机构id",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "id", value = "id",  paramType = "query", dataType = "String")})
    @RequestMapping(value = "/update.htm", method = {RequestMethod.POST})
    @Log(title = "修改节点人员信息",businessModule = "安全机构人员", businessManipulation = BusinessManipulation.UPDATE)
    public MessageBean<?> update(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore SafetyOrgStaff bean) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.update(bean, user);
    }

    @ApiOperation("查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "人员名称",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orgId", value = "机构id",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "keyword", value = "关键词",  dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页",  paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数",  paramType = "query", dataType = "Integer")})
    @RequestMapping(value = "/query.htm", method = {RequestMethod.GET})
    public MessageBean<?> query(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String name, String orgId,String keyword , Integer page, Integer pageSize) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.list(name, orgId, page, pageSize,keyword);
    }
}
